﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Apex.Common.Base;
using Apex.Common.Models;

namespace Apex.Script.Models
{
    public interface ISceneObject
    {
        string Type { get; set; }
    }

    public class DialogueItem
    {
        public Character Character { get; set; }
        public string Line { get; set; }
        public string Directions { get; set; }
    }

    public class SceneDialogue : TrackableObject, ISceneObject, ICollectionContainer<DialogueItem>
    {
        public string Type { get; set; }
        public ICollection<DialogueItem> Items { get; set; }

        public SceneDialogue()
        {
            Items = new List<DialogueItem>();
            Type = GetType().Name;
        }
    }

    public class SceneDescription : TrackableObject, ISceneObject
    {
        public string Description { get; set; }
        public string Type { get; set; }
        //public ICollection<Uri> Items { get; set; }

        public SceneDescription()
        {
            //Items = new List<Uri>();
            Type = GetType().Name;
        }
    }

    public class Scene : NamedTrackableObject, ICollectionContainer<ISceneObject>
    {
        private List<Character> _chars = new List<Character>();

        public string Description { get; set; }
        public Location Location { get; set; }

        public ICollection<ISceneObject> Items { get; set; }
        public List<Character> Characters
        {
            get
            {
                _chars.Clear();
                foreach (var x in Items)
                {
                    if (x.Type == "SceneDialogue")
                    {
                        var dlg = (x as SceneDialogue);
                        foreach (var y in dlg.Items)
                        {
                            if (_chars.Contains(y.Character))
                                continue;

                            _chars.Add(y.Character);
                        }
                    }
                }
                return _chars;
            }
        }

        public Scene()
        {
            Items = new List<ISceneObject>();
        }
    }
}
